package lambda.cart;

import com.sun.corba.se.impl.orbutil.StackImpl;

import java.util.ArrayList;
import java.util.List;

/**
 *@Author:fengxiaohui
 *@Description: 购物车服务类
 *@Date:Create in 23:28 2024/12/9
 *@Modified By:
 */
public class CartService {
    //加入到购物车中的商品信息
    private static List<Sku> cartSkuList = new ArrayList<Sku>(){
        {
            add(new Sku(654032,"无人机",4999.00,1,
            4999.00,SkuCategoryEnum.ELECTRONICS));
            add(new Sku(642934,"VR一体机",2299.00,1,
                    2299.00,SkuCategoryEnum.ELECTRONICS));
            add(new Sku(645321,"格子衬衫",409.00,3,
                    1227.00,SkuCategoryEnum.CLOTHING));
            add(new Sku(654327,"牛仔裤",528.00,1,
            528.00,SkuCategoryEnum.CLOTHING));
            add(new Sku(675489,"跑步机",2699.00,1,
                    2699.00,SkuCategoryEnum.SPORTS));
            add(new Sku(644564,"Java编程思想",79.80,1,
                    79.80,SkuCategoryEnum.BOOKS));
            add(new Sku(678678,"Java核心技术",149.00,1,
                    149.00,SkuCategoryEnum.BOOKS));
            add(new Sku(697894,"算法",78.20,1,
                    78.20,SkuCategoryEnum.BOOKS));
            add(new Sku(696968,"TensortFlow进阶指南",85.10,1,
                    85.0,SkuCategoryEnum.BOOKS));
        }
    };

    /**
    * @Description: 获取商品信息列表
    * @Param:
    * @Author: fengxiaohui
    * @Date: 2024/12/9
    */
    public static List<Sku> getCartSkuList(){
        return cartSkuList;
    }

    /**
    * @Description: 找出购物车中的电子产品
    * @Param:
    * @Author: fengxiaohui
    * @Date: 2024/12/10
    */
    public static List<Sku> filterElectronicsSkus(List<Sku> cartSkuList){
        List<Sku> result = new ArrayList<Sku>();
        for (Sku sku: cartSkuList) {
            //如果商品类型 等于 数码类
            if (SkuCategoryEnum.ELECTRONICS.equals(sku.getSkuCartgory())){
                result.add(sku);
            }
        }
        return result;
    }

    public static List<Sku> filterSkusByCategory(List<Sku> cartSkuList,SkuCategoryEnum categoryEnum){
        List<Sku> result = new ArrayList<>();
        for (Sku sku: cartSkuList
             ) {
            // 商品类型 等于 用户输入的参数
           if(categoryEnum.equals(sku.getSkuCartgory())){
               result.add(sku);
           }
        }
        return result;

    }
    /**
    * @Description: Version3.0
    * @Param: 支持通过商品类型或者总价过滤商品
     * categoryOrPrice - true 根据：商品类型，false-根据商品总价
    * @Author: fengxiaohui
    * @Date: 2024/12/10
    */
    public static List<Sku> filterSkus(List<Sku> cartSkuList,SkuCategoryEnum categoryEnum ,
                                      Double totalPrice, Boolean categoryOrPrice ){
        List<Sku> result = new ArrayList<Sku>();
        for (Sku sku: cartSkuList
             ) {
            if ((categoryOrPrice && categoryEnum.equals(sku.getSkuCartgory())) ||
                    (!categoryOrPrice && sku.getTotalPrice() > totalPrice)){
                result.add(sku);
            }
        }
        return result;
    }

    /**
    * @Description:
    * @Param:
    * @Author: fengxiaohui
    * @Date: 2024/12/10
    */
    public List<Sku> filterSkus(){

        return null;
    }



}
